<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
      <!--      <el-form-item label="商家名称" prop="merName">-->
      <!--        <el-input-->
      <!--            v-model="queryParams.merName"-->
      <!--            placeholder="请输入商家名称"-->
      <!--            clearable-->
      <!--            @keyup.enter="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="套餐名称" prop="prodName">
        <el-input
            v-model="queryParams.prodName"
            placeholder="请输入套餐名称"
            clearable
            @keyup.enter="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="运动类型" prop="prodCatalogId">-->
      <!--        <el-select v-model="queryParams.prodCatalogId" placeholder="请选择运动类型" clearable>-->
      <!--          <el-option-->
      <!--              v-for="dict in play_sport_type"-->
      <!--              :key="dict.value"-->
      <!--              :label="dict.label"-->
      <!--              :value="dict.value"-->
      <!--          />-->
      <!--        </el-select>-->
      <!--      </el-form-item>-->
<!--      <el-form-item label="活动人数" prop="maxPeoples">-->
<!--        <el-input-->
<!--            v-model="queryParams.maxPeoples"-->
<!--            placeholder="请输入活动人数"-->
<!--            clearable-->
<!--            @keyup.enter="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="是否免费" prop="isFree">
        <el-select v-model="queryParams.isFree" placeholder="请选择运动类型" clearable>
          <el-option
              v-for="dict in t_is_yes"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['system:tplayprod:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['system:tplayprod:remove']"
        >删除
        </el-button>
      </el-col>
      <!--      <el-col :span="1.5">-->
      <!--        <el-button-->
      <!--            type="warning"-->
      <!--            plain-->
      <!--            icon="Download"-->
      <!--            @click="handleExport"-->
      <!--            v-hasPermi="['system:tplayprod:export']"-->
      <!--        >导出-->
      <!--        </el-button>-->
      <!--      </el-col>-->
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="tprodList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <!--      <el-table-column label="商家名称" align="center" prop="merName">-->
      <!--        <template #default="scope">-->
      <!--          <span style="color:red;" v-if="scope.row.merStatus =='04'">{{ scope.row.merName }}</span>-->
      <!--          <span v-else>{{ scope.row.merName }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="套餐名称" align="center" prop="prodName"/>
      <!--      <el-table-column label="活动类型" align="center" prop="type">-->
      <!--        <template #default="scope">-->
      <!--          <dict-tag :options="t_prod_type" :value="scope.row.type"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="报名时间" align="center" prop="saleStartTime" width="190">
        <template #default="scope">
          <span>{{
              parseTime(scope.row.saleStartTime, '{y}-{m}-{d} {h}:{i}')
            }}至{{ parseTime(scope.row.saleEndTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <!--      <el-table-column label="活动时间" align="center" prop="effStartTime" width="190">-->
      <!--        <template #default="scope">-->
      <!--          <span>{{-->
      <!--              parseTime(scope.row.effStartTime, '{y}-{m}-{d}')-->
      <!--            }}至{{ parseTime(scope.row.effEndTime, '{y}-{m}-{d}') }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
<!--      <el-table-column label="活动人数" align="center" prop="maxPeoples"/>-->
      <!--      <el-table-column label="运动类型" align="center" prop="prodCatalogId">-->
      <!--        <template #default="scope">-->
      <!--          <dict-tag :options="play_sport_type" :value="scope.row.prodCatalogId"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="是否免费" align="center" prop="isFree">
        <template #default="scope">
          <dict-tag :options="t_is_yes" :value="scope.row.isFree"/>
        </template>
      </el-table-column>
      <el-table-column label="标准价格" align="center" prop="price"/>
      <el-table-column label="销售价格" align="center" prop="salePrice"/>
      <el-table-column label="库存数量" align="center" prop="store"/>
      <!--      <el-table-column label="是否公开" align="center" prop="isPublic">-->
      <!--        <template #default="scope">-->
      <!--          <dict-tag :options="t_is_yes" :value="scope.row.isPublic"/>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="操作" align="center" width="350" class-name="small-padding fixed-width" fixed="right">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
                     :class="{'but-disabled': !(scope.row.merStatus === '02')}"
                     v-hasPermi="['system:tplayprod:edit']">修改
          </el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
                     :class="{'but-disabled': !(scope.row.merStatus === '02')}"
                     v-hasPermi="['system:tplayprod:remove']">删除
          </el-button>
          <el-button link type="primary" icon="Wallet" @click="handlePrice(scope.row)"
                     :class="{'but-disabled': !(scope.row.merStatus === '02' && scope.row.isFree === 0)}"
                     v-hasPermi="['system:tplayprod:price']">定价
          </el-button>
          <!--          <el-button link type="primary" icon="Upload" @click="handlePublish(scope.row)"-->
          <!--                     :class="{'but-disabled': !(scope.row.merStatus === '02' && scope.row.publishCount === 0)}"-->
          <!--                     v-hasPermi="['system:tplayprod:publish']">上架-->
          <!--          </el-button>-->
          <!--          <el-button link type="primary" icon="Download" @click="handleCancelPublish(scope.row)"-->
          <!--                     :class="{'but-disabled': !(scope.row.merStatus === '02' && scope.row.publishCount > 0)}"-->
          <!--                     v-hasPermi="['system:tplayprod:publish']">下架-->
          <!--          </el-button>-->
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
    />

    <!-- 添加或修改套餐列表对话框 -->
    <el-dialog :title="title" v-model="open" width="1000px" append-to-body>
      <el-form ref="tprodRef" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <!--          <el-col :span="12">-->
          <!--            <el-form-item label="商家名称" prop="merId">-->
          <!--              <mer-select :key="refreshTime" v-model="form.merId" :typeList=[2]-->
          <!--                          :disabledValue="disableNum"></mer-select>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <el-col :span="12">
            <el-form-item label="套餐名称" prop="prodName">
              <el-input v-model="form.prodName" placeholder="请输入套餐名称"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报名时间" prop="saleStartTime">
              <el-date-picker
                  clearable
                  v-model="saleTimeRange"
                  type="datetimerange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  format="YYYY-MM-DD HH:mm"
                  value-format="YYYY-MM-DD HH:mm"
                  @change="handleSaleTimeChange"
              ></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <!--        <el-row>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="主图" prop="prodMainPic">-->
        <!--              <image-upload v-model="form.prodMainPic" :limit="1"/>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="详情图" prop="prodDetailPic">-->
        <!--              <image-upload v-model="form.prodDetailPic" :limit="9"/>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
        <!--        <el-row>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="群聊码" prop="chatPic">-->
        <!--              <image-upload v-model="form.chatPic" :limit="1"/>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="运动类型" prop="prodCatalogId">-->
        <!--              <el-select v-model="form.prodCatalogId" placeholder="请选择运动类型">-->
        <!--                <el-option-->
        <!--                    v-for="dict in play_sport_type"-->
        <!--                    :key="dict.value"-->
        <!--                    :label="dict.label"-->
        <!--                    :value="parseInt(dict.value)"-->
        <!--                ></el-option>-->
        <!--              </el-select>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
        <!--        <el-row>-->

        <!--                    <el-col :span="12">-->
        <!--                      <el-form-item label="活动时间" prop="effStartTime">-->
        <!--                        <el-date-picker-->
        <!--                            clearable-->
        <!--                            v-model="validTimeRange"-->
        <!--                            type="daterange"-->
        <!--                            range-separator="至"-->
        <!--                            start-placeholder="开始日期"-->
        <!--                            end-placeholder="结束日期"-->
        <!--                            value-format="YYYY-MM-DD"-->
        <!--                            @change="handleValidTimeChange"-->
        <!--                        ></el-date-picker>-->
        <!--                      </el-form-item>-->
        <!--                    </el-col>-->
        <!--        </el-row>-->
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否免费" prop="isFree">
              <el-select v-model="form.isFree" placeholder="请选择是否免费"  @change="chooseFree">
                <el-option
                    v-for="dict in t_is_yes"
                    :key="dict.value"
                    :label="dict.label"
                    :value="parseInt(dict.value)"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12" v-if="form.isFree === 0">
            <el-form-item label="标准价格" prop="price">
              <!-- <el-input v-model="form.price" placeholder="请输入标准价格" type="number" min="1"/> -->
              <el-input-number v-model="form.price" :max="999999" :min="0.01"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!--          <el-col :span="12">-->
          <!--            <el-form-item label="活动人数" prop="maxPeoples">-->
          <!--              &lt;!&ndash; <el-input v-model="form.maxPeoples" placeholder="请输入活动人数" type="number"/> &ndash;&gt;-->
          <!--              <el-input-number v-model="form.maxPeoples" :max="999999" :min="1" step-strictly/>-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <el-col :span="12">
            <el-form-item label="库存数量" prop="store">
              <!-- <el-input v-model="form.store" placeholder="请输入库存数量" type="number"/> -->
              <el-input-number v-model="form.store" :max="999999" :min="1" step-strictly/>
            </el-form-item>
          </el-col>
        </el-row>
        <!--        <el-row>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="地区" prop="areaCode">-->
        <!--              <el-cascader-area v-model="form.areaCode"-->
        <!--                                :is-save="useUserStore().userType === '0' ?true:false"></el-cascader-area>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--          <el-col :span="12">-->
        <!--            <el-form-item label="详细地址" prop="addr">-->
        <!--              <el-input v-model="form.addr" placeholder="请输入详细地址"/>-->
        <!--            </el-form-item>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
        <!--        <el-row>-->
        <!--          <el-col :span="24">-->
        <!--            <map-component :key="mapComponentKey"-->
        <!--                           :longitude="form.longitude" :latitude="form.latitude"-->
        <!--                           @coordinateClicked="handleCoordinateClicked"-->
        <!--            ></map-component>-->
        <!--          </el-col>-->
        <!--        </el-row>-->
        <el-row>
          <el-col :span="24">
            <el-form-item label="描述" prop="prodDesc">
              <editor v-model="form.prodDesc" :min-height="192"/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Tplayprod">
import {listTplayprod, getTprod, delTprod, addTprod, updateTprod, playPublish} from "@/api/system/tprod";
import {onBeforeUnmount, onMounted, ref, watch} from "vue";
import MerSelect from "@/components/MerSelect/index.vue";
import useUserStore from "@/store/modules/user";
import router from "@/router";
import {getAreaCode} from "@/api/system/sysCity";
import {ElMessage} from 'element-plus'

const route = useRoute();

const {proxy} = getCurrentInstance();
const {
  t_is_yes,
  package_service_time,
  package_reserve_info,
  shop_type,
  ty_play_type,
  effective_time,
  play_sport_type,
  t_prod_type
} = proxy.useDict('t_is_yes', 'package_service_time', 'package_reserve_info', 'shop_type', 'ty_play_type', 'effective_time', 'play_sport_type', 't_prod_type');

const tprodList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const saleTimeRange = ref([]);
const validTimeRange = ref([]);
const disableNum = ref(0);
const mapComponentKey = ref(0);
const refreshTime = ref(0); //组件刷新次数

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    ownerId: undefined,
    merId: undefined,
    prodName: undefined,
    prodDesc: undefined,
    prodCatalogId: undefined,
    type: undefined,
    typeList: [2, 3],
    saleStartTime: undefined,
    saleEndTime: undefined,
    effTime: undefined,
    effStartTime: undefined,
    effEndTime: undefined,
    reserveInfo: undefined,
    serviceTime: undefined,
    maxPeoples: undefined,
    isPublic: undefined,
    limitTimes: undefined,
    store: undefined,
    sold: undefined,
    isFree: undefined,
    price: undefined,
    cityCode: undefined,
    areaCode: undefined,
    areaPath: undefined,
    addr: undefined,
    addrDesc: undefined,
    status: undefined,
  },
  rules: {
    // merId: [
    //   {required: true, message: "商家名称不能为空", trigger: "blur"}
    // ],
    prodName: [
      {required: true, message: "套餐名称不能为空", trigger: "blur"}
    ],
    maxPeoples: [
      {required: true, message: "活动人数不能为空", trigger: "blur"}
    ],
    // prodDesc: [
    //   {required: true, message: "描述不能为空", trigger: "blur"}
    // ],
    prodMainPic: [
      {required: true, message: "主图不能为空", trigger: "blur"}
    ],
    prodDetailPic: [
      {required: true, message: "详情图不能为空", trigger: "blur"}
    ],
    chatPic: [
      {required: true, message: "群聊码不能为空", trigger: "blur"}
    ],
    isFree: [
      {required: true, message: "是否免费不能为空", trigger: "change"}
    ],
    limitTimes: [
      {required: true, message: "限购人数不能为空", trigger: "blur"}
    ],
    prodCatalogId: [
      {required: true, message: "运动类型不能为空", trigger: "blur"}
    ],
    store: [
      {required: true, message: "不能为空", trigger: "blur"},
      // {
      //   validator: (rule, value, callback) => {
      //     if (form.packageableType === 'Business') {
      //       callback();
      //     }
      //     if (value > editPersonNum.value) {
      //       if (editPersonNum.value > 0) {
      //         callback(new Error("人数不能大于人数" + editPersonNum.value));
      //       }
      //       callback();
      //
      //     } else {
      //       callback();
      //     }
      //   },
      //   trigger: "blur"
      // }
    ],
    areaCode: [
      {required: true, message: "地区不能为空！", trigger: "change"},
    ],
    addr: [
      {required: true, message: "详细地址不能为空！", trigger: "change"},
    ],
    saleStartTime: [
      {required: true, message: "报名时间不能为空！", trigger: "change"},
    ],
    effStartTime: [
      {required: true, message: "活动时间不能为空！", trigger: "change"},
    ],
    price: [
      {required: true, message: "价格不能为空", trigger: "change"},
    ]
    // validTime: [
    //   {required: true, message: "请选择活动时间", trigger: "blur"},
    //   {
    //     validator: checkValidTimeRange,
    //     trigger: 'change'
    //   }
    // ],
  }
});

const {queryParams, form, rules} = toRefs(data);
onMounted(() => {
  form.value.ownerId = route.query.playId
  form.value.merId = route.query.merId
});

/** 查询套餐列表列表 */
function getList() {
  loading.value = true;
  queryParams.value.merId = route.query.merId
  queryParams.value.ownerId = route.query.playId
  listTplayprod(queryParams.value).then(response => {
    tprodList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

function chooseFree() {
  if(form._object.form.isFree == 0) {
    rules._object.rules.price[0].required = true
  } else {
    rules._object.rules.price[0].required = false
  }
}

// 取消按钮
function cancel() {
  open.value = false;
  reset();
}

// 表单重置
function reset() {
  form.value = {
    prodId: undefined,
    merId: undefined,
    prodName: undefined,
    prodMainPic: undefined,
    prodDetailPic: undefined,
    prodDesc: undefined,
    chatPic: undefined,
    prodCatalogId: undefined,
    type: 2,
    saleStartTime: undefined,
    saleEndTime: undefined,
    effTime: undefined,
    effStartTime: undefined,
    effEndTime: undefined,
    reserveInfo: undefined,
    serviceTime: undefined,
    maxPeoples: undefined,
    isPublic: undefined,
    limitTimes: undefined,
    store: undefined,
    sold: undefined,
    isFree: undefined,
    price: undefined,
    cityCode: undefined,
    areaCode: undefined,
    areaPath: undefined,
    addr: undefined,
    addrDesc: undefined,
    longitude: 118.8083,
    latitude: 31.8639,
    sortNum: undefined,
    status: undefined,
    statusReason: undefined,
    auditTime: undefined,
    auditor: undefined,
    ext1: undefined,
    ext2: undefined,
    ext3: undefined,
    state: undefined,
    createTime: undefined,
    creator: undefined,
    modifyTime: undefined,
    modifier: undefined
  };
  mapComponentKey.value += 1;
  proxy.resetForm("tprodRef");
  saleTimeRange.value = [];
  validTimeRange.value = [];
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

// 定价
function handlePrice(row) {
  router.push('/system/tprice/index/' + row.prodId)
}

function handlePublish(row) {
  proxy.$modal.confirm('是否确认上架活动，编号为"' + row.prodId + '"的数据项？').then(function () {
    row.isPublish = 1;
    return playPublish(row);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("上架成功");
  }).catch(() => {
  });
}

function handleCancelPublish(row) {
  proxy.$modal.confirm('是否确认下架活动，编号为"' + row.prodId + '"的数据项？').then(function () {
    row.isPublish = 0;
    return playPublish(row);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("下架成功");
  }).catch(() => {
  });
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.prodId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  refreshTime.value += 1
  disableNum.value = 0

  reset();
  open.value = true;
  title.value = "添加套餐";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  refreshTime.value += 1
  disableNum.value = 1

  reset();

  const _prodId = row.prodId || ids.value
  getTprod(_prodId).then(response => {
    console.log(response.data)
    form.value = response.data;
    saleTimeRange.value = [response.data.saleStartTime, response.data.saleEndTime];
    validTimeRange.value = [response.data.effStartTime, response.data.effEndTime];
    open.value = true;
    title.value = "修改套餐";
  });
}

/** 提交按钮 */
function submitForm() {
  form.value.ownerId = route.query.playId
  form.value.merId = route.query.merId
  // if (form.value.effStartTime < form.value.saleStartTime) {
  //   ElMessage.error('活动开始时间不能小于报名开始时间哦！')
  //   return
  // }
  // if (form.value.effEndTime < form.value.saleEndTime) {
  //   ElMessage.error('活动结束时间不能小于报名结束时间哦！')
  //   return
  // }
  proxy.$refs["tprodRef"].validate(valid => {
    if (valid) {
      if (form.value.prodId != null) {
        updateTprod(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addTprod(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _prodIds = row.prodId || ids.value;
  proxy.$modal.confirm('是否确认删除套餐编号为"' + _prodIds + '"的数据项？').then(function () {
    return delTprod(_prodIds);
  }).then(() => {
    getList();
    proxy.$modal.msgSuccess("删除成功");
  }).catch(() => {
  });
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('system/tprod/export', {
    ...queryParams.value
  }, `tprod_${new Date().getTime()}.xlsx`)
}

function handleSaleTimeChange(value) {
  if (value && value.length === 2) {
    form.value.saleStartTime = value[0];
    form.value.saleEndTime = value[1];
  }
}

function handleValidTimeChange(value) {
  if (value[0] < form.value.saleStartTime) {
    ElMessage.error('活动开始时间不能小于报名开始时间哦！')
  }
  if (value[1] < form.value.saleEndTime) {
    ElMessage.error('活动结束时间不能小于报名结束时间哦！')
  }
  if (value && value.length === 2) {
    form.value.effStartTime = value[0];
    form.value.effEndTime = value[1];
  }
}

function checkValidTimeRange(rule, value, callback) {
  const saleEndTime = saleTimeRange.value ? saleTimeRange.value[1] : null;
  const effEndTime = validTimeRange.value ? validTimeRange.value[1] : null;
  if (saleEndTime && saleEndTime > effEndTime.value) {
    callback(new Error('报名结束时间不能大于活动结束时间:' + effEndTime.value));
  } else {
    callback();
  }
}

function handleCoordinateClicked(coordinate) {
  // 更新经纬度
  form.value.longitude = coordinate.lng;
  form.value.latitude = coordinate.lat;
  form.value.addr = coordinate.addr;
  getAreaCode({
    provinceExtName: coordinate.province,
    cityExtName: coordinate.city,
    districtExtName: coordinate.district
  }).then(response => {
    form.value.areaCode = response.data.district;
  });
}

getList();
const stopWatching = watch(() => useUserStore().cascaderKey, (v) => {
  getList();
}, {immediate: true});
onBeforeUnmount(() => {
  stopWatching();
});
</script>
